<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改APP版本')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-appEdition-edit" th:object="${appEdition}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">appId：</label>
                <div class="col-sm-8">
                    <input name="appId" th:field="*{appId}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">版本号：</label>
                <div class="col-sm-8">
                    <input name="editionCode" th:field="*{editionCode}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">应用名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <textarea name="content" class="form-control" th:field="*{content}"></textarea>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机型号：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:field="*{type}">
                        <option value="1">安卓</option>
                        <option value="2">苹果</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">强制更新：</label>
                <div class="col-sm-8">
                    <select name="renew" class="form-control m-b" th:field="*{renew}">
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">包类型：</label>
                <div class="col-sm-8">
                    <select name="wrapType" class="form-control m-b"  th:field="*{wrapType}">
                        <option value="wgt">wgt</option>
                        <option value="app">app</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">上传：</label>
                <div class="col-sm-8">
                    <input type="file" name="upload" id="upload" style="display: none;"/>
                    <input type="hidden" id="fileType" style="display: none;"/>
                    <a class="btn btn-success" onclick="onFile()">
                        <i class="fa fa-plus"></i> 下载地址
                    </a>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">下载地址：</label>
                <div class="col-sm-8">
                    <input name="url" th:field="*{url}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">应用地址：</label>
                <div class="col-sm-8">
                    <input id="storeUrl" name="storeUrl" th:field="*{storeUrl}" class="form-control" type="text" >
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "sso/appEdition";
        $("#form-appEdition-edit").validate({
            focusCleanup: true
        });

        var isClick = true;
        function submitHandler() {
            if ($.validate.form() && isClick) {
                isClick = false;
                $.operate.save(prefix + "/edit", $('#form-appEdition-edit').serialize());
            }
        }

        $("input[name='created']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
        function onFile() {
            $('#upload').click();
        }

        $('#upload').on('change', function () {
            var farmdate = new FormData();
            farmdate.append("file", $('#upload')[0].files[0]);
            $.ajax({
                type: "post",
                url: "/common/importFile",
                data: farmdate,
                contentType: false,
                processData: false,
                success: function (date) {
                    $('#url').val(date);
                }
            })
        });
    </script>
</body>
</html>